<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<div  style="width: 400px; margin: 100px auto;text-align:center; border:2px solid #aaa">

<div style="margin: 20px">
    用户名：<input type="text"id="usernameInput">
</div>
    <div style="margin: 20px">
        密码：<input type="password" id="passwordInput">
    </div>
<div style="margin: 20px">
    <button onclick="login()">登录</button>
</div>

</div>
<script>
    function login(){
  var username  = document.getElementById("usernameInput").value
  var password  = document.getElementById("passwordInput").value


        fetch("/user/login",{
      method:'POST',
      headers:{
          'Content-Type':'application/json'
      },
      body:JSON.stringify({username:username, password:password})

      }).then(res => {
            console.log(res)
            return res.text()
        }).then(res => {
            console.log(res)
         if (res === 'SUCCESS'){
             location.href='/'
         }else {
            alert(" 密码或者账号错误")

         }

      })
    }

</script>
</body>
</html>

